package cn.linzelin.dao;

import cn.linzelin.po.user;
import jdk.nashorn.internal.ir.WhileNode;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class Dao {
    public static List<user> getList() throws Exception {

        //加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //先获取connection对象
        Connection connection = DriverManager.getConnection("jdbc:mysql:///blog","root", "root");
        //获取操作数据库的对象
        PreparedStatement pre = connection.prepareCall("select * from userblog");
        //执行数据库
        ResultSet resultSet = pre.executeQuery();
        List<user> list = new ArrayList<>();
        while(resultSet.next()){
            user user = new user();
            user.setAccount(resultSet.getInt("uid"));
            user.setName(resultSet.getString("title"));
            user.setPassword(resultSet.getString("content"));
            list.add(user);
        }
        connection.close();
        pre.close();
        resultSet.close();
        return list;
    }
}
